/*
 * This file is part of GuitarMaster.
 * 
 * GuitarMaster is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GuitarMaster is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with GuitarMaster.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.paris5.master2.guitarmaster.exception;

/*
 * $Id: EcomException.java 8 2013-03-13 08:38:14Z nedjahi.mourad@gmail.com $
 * 
 * $HeadURL: http://com-paris5-master2-guitarmaster-distrib.googlecode.com/svn/trunk/com.paris5.master2.guitarmaster.distrib/src/com/paris5/master2/guitarmaster/exception/EcomException.java $
 * $Revision: 8 $
 * $Date: 2013-03-13 08:38:14 +0000 (Wed, 13 Mar 2013) $
 * $Author: nedjahi.mourad@gmail.com $
 */

/**
 * @author Leticia Mahamed, Alice Khammy, mourad nedjahi, Saliou Mamadou Barry
 * 
 * Exception generique
 */
public class EcomException extends Exception{
    
    public static enum Level{INFO, WARNING, ERROR};
    private String name;
    private Object object;
    private Level level;
    
    public EcomException(){
        super();
        this.level = Level.ERROR;   
        this.object = this.name = null;
    }
    
    public EcomException(Object obj) {
        this.name = obj != null? obj.getClass().getName() : "null";
        this.level = Level.ERROR;
        this.object = obj;
    }
    
    public EcomException(Object obj,String message) {
        super(message);
        this.name = obj != null? obj.getClass().getName() : "null";
        this.level = Level.ERROR;
        this.object = obj;
    }
    
    public EcomException(Object obj,String message, Level level) {
        super(message);
        this.name = obj != null? obj.getClass().getName() : "null";
        this.level = level;
        this.object = obj;
    }

    public void setLevel(Level level) {
        this.level = level;
    }

    public void setObject(Object obj) {
        this.name = obj.getClass().getName();
        this.object = obj;
    }

    protected Level getLevel() {
        return level;
    }

    protected Object getObject() {
        return object;
    }
    
    @Override
    public String toString()
    {
        StringBuilder stb = new StringBuilder();
        stb.append(super.toString());
        stb.append(" : Level(").append(level.toString()).append(") Class(").append(this.name).append(") ");

        return stb.toString();
    }
}